/*******************************************************************************
																				
	DESCRIPTION:  	This do file produces Appendix Table A8.
	
*******************************************************************************/

clear all
global id_code 134
set seed 2110

/*******************************************************************************
*	Load stored results
********************************************************************************/
estimates use "${output}/${id_code}_TwoSpell_Analysis_LTU.ster"


/*******************************************************************************
*	Fixed vs Variable / Obs vs Non-obs table: LTU x Two-spell sample
********************************************************************************/

* Table without vertical lines:
file open myfile using "${output}/${id_code}_TwoSpells_Table_LTU.tex", write replace
	
file write myfile "\documentclass{article}" _newline ///
	"\usepackage{multirow}" _newline ///
	"\usepackage{booktabs}" _newline ///	
	"\usepackage[margin=1in]{geometry}" _newline ///
	"\begin{document}" _newline ///
	"\begin{table}[h] \centering" _newline ///
	"\begin{tabular}{@{\extracolsep{6pt}} l c c c c c}" _newline ///
	"\hline \hline \addlinespace[0.2cm]" _newline ///

cap frame drop tabl
frame create tabl str30(obs) double(multLTU_pers multLTU_trans multLTU_total mult_total ref_total)
frame post tabl ("Observable") (_b[ltu_0y:v_obs_pers]) (_b[ltu_0y:v_obs_trans]) (_b[ltu_0y:v_obs]) (_b[ltu_0y:v_obs_twospell]) (_b[ltu_0y:v_obs_control])
frame post tabl ("") (_se[ltu_0y:v_obs_pers]) (_se[ltu_0y:v_obs_trans]) (_se[ltu_0y:v_obs]) (_se[ltu_0y:v_obs_twospell]) (_se[ltu_0y:v_obs_control])
frame post tabl ("Unobservable") (_b[ltu_0y:v_unobs_pers]) (.) (.) (.) (.)
frame post tabl ("") (_se[ltu_0y:v_unobs_pers]) (.) (.) (.) (.)
frame post tabl ("Total") (_b[ltu_0y:v_pers]) (.) (_b[ltu_0y:v]) (_b[ltu_0y:v_twospell]) (_b[ltu_0y:v_control])
frame post tabl ("") (_se[ltu_0y:v_pers]) (.) (_se[ltu_0y:v]) (_se[ltu_0y:v_twospell]) (_se[ltu_0y:v_control])
frame tabl: export delimited using "${output}/${id_code}_TwoSpells_Table_LTU.csv", replace

* Write to table:	
file write myfile ///
	"& \multicolumn{5}{c}{\large \textbf{`title'}} \\ \addlinespace[1.5ex]" _newline ///
	"& \multicolumn{3}{c}{Multiple Spells, LTU Sample} & Multiple Spells Sample & Control Sample \\  \addlinespace[0.1cm]" _newline ///
	"\cline{2-4} \cline{5-5} \cline{6-6} \addlinespace[0.1cm]" _newline ///
	"\hspace{2cm} & \textbf{Persistent} & \textbf{Transitory} & \textbf{Total} & \textbf{Total} & \textbf{Total} \\ \addlinespace[0.2cm]" _newline ///
	"\multirow{2}{*}{\textbf{Observable}} & \(C_1 = Cov_{6, 0}^{t_1,t_2}(\hat{F}_{i, 6}^{1}, F_{0}^{t_2})\) & \(C_3 - C_1 \)  & \( C_3 = Cov_{6, 0}^{t_1, t_2}(\hat{F}_{i, 6}^{2}, F_{0}^{t_2})\) & \( C_4 = Cov_{0, 0}^{t_1, t_2}(\hat{F}_{i, 6}^{2}, F_{0}^{t_2})\) & \( C_5 = Cov_{0}^{t_2}(\hat{F}_{i, 6}^{2}, F_{0}^{t_2})\) \\" _newline ///
	" & \textbf{`: di %5.3f _b[ltu_0y:v_obs_pers]'} & \textbf{`: di %5.3f _b[ltu_0y:v_obs_trans]'} & \textbf{`: di %5.3f _b[ltu_0y:v_obs]'} & \textbf{`: di %5.3f _b[ltu_0y:v_obs_twospell]'} & \textbf{`: di %5.3f _b[ltu_0y:v_obs_control]'} \\" _newline ///
	" & (`: di %5.4f _se[ltu_0y:v_obs_pers]') & (`: di %5.4f _se[ltu_0y:v_obs_trans]') & (`: di %5.3f _se[ltu_0y:v_obs]') & (`: di %5.4f _se[ltu_0y:v_obs_twospell]') & (`: di %5.3f _se[ltu_0y:v_obs_control]') \\ \addlinespace[0.2cm]" _newline ///
	"\multirow{2}{*}{\textbf{Unobservable}} & \( C_2 - C_1 \) & & & &  \\" _newline ///
	" & \textbf{`: di %5.3f _b[ltu_0y:v_unobs_pers]'} & & & & \\" _newline ///
	" & (`: di %5.4f _se[ltu_0y:v_unobs_pers]') & & & & \\ \addlinespace[0.2cm]" _newline ///
	"\cline{2-4} \cline{5-5} \cline{6-6} \addlinespace[0.2cm]" _newline ///
	"\multirow{2}{*}{\textbf{Total}} & \( C_2 = Cov_{6, 0}^{t_1, t_2}(F_{i, 6}^{1}, F_{0}^{t_2}) \) & & \textit{By Proportionality} & \textit{By Proportionality} & \textit{By Proportionality} \\" _newline ///
	"& \textbf{`: di %5.3f _b[ltu_0y:v_pers]'} & & \textit{`: di %5.3f _b[ltu_0y:v]'} & \textit{`: di %5.3f _b[ltu_0y:v_twospell]'} & \textit{`: di %5.3f _b[ltu_0y:v_control]'} \\" _newline ///
	"& (`: di %5.4f _se[ltu_0y:v_pers]') & & \textit{(`: di %5.4f _se[ltu_0y:v]')} & \textit{(`: di %5.4f _se[ltu_0y:v_twospell]')} & \textit{(`: di %5.4f _se[ltu_0y:v_control]')} \\  \addlinespace[0.2cm]" _newline ///
	"\addlinespace[6ex]" _newline ///

file write myfile ///
	"\addlinespace[-5ex]" _newline ///
	"\hline \hline" _newline ///
	"\end{tabular}" _newline ///
	"\end{table}" _newline ///
	"\end{document}"

file close myfile		